//
//  MTPubMarkCell1.m
//  met
//
//  Created by 李晓俊 on 2019/6/13.
//  Copyright © 2019 李晓俊. All rights reserved.
//

#import "MTPubMarkCell1.h"

@implementation MTPubMarkCell1

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+(MTPubMarkCell1 *)cellWithTableView:(UITableView *)tableview{
    static NSString* ID =  @"MTPubMarkCell1";
    MTPubMarkCell1* cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //    cell.backgroundColor = [UIColor clearColor];
    
    return cell;
}

- (void)setImgArr:(NSArray *)imgArr {
    _imgArr = imgArr;
    
    CGFloat wid = 100;
//    (kScreenWidth - 36 - 3*10 )/4.0;
    
    NSInteger num = imgArr.count;
    CGFloat width ;
    if ((num+1)*(wid + 10) + 20 > kScreenWidth) {
        width = (num+1)*(wid + 10);
    }else {
        width  =  kScreenWidth;
    }
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 20 * 2, wid)];
    [self.imgBgView addSubview:scroll];
    scroll.contentSize=CGSizeMake(width, wid);
    scroll.bounces=NO;
    scroll.alwaysBounceHorizontal  = YES;//水平
    scroll.alwaysBounceVertical = NO; //垂直
    scroll.showsVerticalScrollIndicator = NO; //垂直滚动条
    scroll.showsHorizontalScrollIndicator= NO; //水平滚动条
    for (int i = 0; i < imgArr.count; i ++) {
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake((wid+10)*i, 0, wid, wid)];
        img.contentMode = 0;
        [scroll addSubview:img];
//        [img sd_setImageWithURL:[NSURL URLWithString:[imgArr objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"默认照片"]];
        img.image = [imgArr objectAtIndex:i];
        
//        img.contentMode = 2;
        //        img.image = ;
        img.tag = 500 + i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick:)];
        img.userInteractionEnabled = YES;
        img.layer.cornerRadius = 4.0f;
        img.layer.masksToBounds = YES;
        [img addGestureRecognizer:tap];
    }
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake((wid+10)*num, 0, 100, 100)];
    [scroll addSubview:img];
    img.image = [UIImage imageNamed:@"添加"];
    img.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addClick)];
    img.contentMode = 1;

    [img addGestureRecognizer:tap];
}
- (void)addClick {
    if (self.imgaddClick) {
        self.imgaddClick(1);
    }
}
- (void)imageClick:(UITapGestureRecognizer *)tap {
    NSInteger tag = tap.view.tag;
    if (self.imgClick) {
        self.imgClick(tag - 500);
    }
}

@end
